/**
 * 
 */
package com.usc.nearbyus;

import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.wifi.ScanResult;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

/**
 * @author pranav
 *
 */
public class WifiList extends ListActivity {	

	private ReadingsDbAdapter mDbAdapter;

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.wifi_list);
		mDbAdapter = new ReadingsDbAdapter(this);
        mDbAdapter.open();
        fillData();
        registerForContextMenu(getListView());
		
		
	}

	private void fillData() {
		
		 Cursor readingsCursor = mDbAdapter.getAllReadings();
	     startManagingCursor(readingsCursor);
	     
	     String[] from = new String[]{mDbAdapter.KEY_SSID,mDbAdapter.KEY_LEVEL,mDbAdapter.KEY_LONGITUDE,mDbAdapter.KEY_LATITUDE};
	     int[] to = new int[]{R.id.wifiname, R.id.wifistrength, R.id.wifilongitude, R.id.wifilatitude};

	     // Now create a simple cursor adapter and set it to display
	        SimpleCursorAdapter readings = 
	            new SimpleCursorAdapter(this, R.layout.wifi_list_item, readingsCursor, from, to);
	        setListAdapter(readings);
		
	}

	 @Override
	    protected void onListItemClick(ListView l, View v, int position, long id) {
	        super.onListItemClick(l, v, position, id);
	        /*Intent i = new Intent(this, ReadingEdit.class);
	        i.putExtra(mDbAdapter.KEY_ROWID, id);
	        startActivityForResult(i, ACTIVITY_EDIT);*/
	    }

	/* (non-Javadoc)
	 * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
	 */
	@Override
	    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
	        super.onActivityResult(requestCode, resultCode, intent);
	        fillData();
	    }

	/* (non-Javadoc)
	 * @see android.app.Activity#onDestroy()
	 */
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
	
	

}
